//
//  PredicateViewController.m
//  GCD
//
//  Created by fangyuan ding on 2020/8/11.
//  Copyright © 2020 fangyuan ding. All rights reserved.
//

#import "PredicateViewController.h"
#import "Student.h"
@interface PredicateViewController ()

@end

@implementation PredicateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   Student *student0 = [[Student alloc] init];
    student0.name = @"Lady Mary Crawley";
    student0.score = 70;
    student0.grade = 6;
        
    Student *student1 = [[Student alloc] init];
    student1.name = @"Lady Edith Crawley";
    student1.score = 90;
    student1.grade = 7;
        
    Student *student2 = [[Student alloc] init];
    student2.name = @"Lady Sybil Crawley";
    student2.score = 98;
    student2.grade = 7;
        
    NSArray *students = @[student0, student1, student2];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K > %d", @"score", 90];
    NSLog(@"predicate.predicateFormat: %@", predicate.predicateFormat);
    NSArray *filterStudents = [students filteredArrayUsingPredicate:predicate];
    [filterStudents enumerateObjectsUsingBlock:^(Student *student, NSUInteger idx, BOOL * _Nonnull stop) {
        NSLog(@"[score > 90] student name is: %@", student.name);
    }];
}



@end
